class BaseUploader < CarrierWave::Uploader::Base
  def store_dir
    "#{model.class.to_s.underscore}/#{mounted_as}"
  end

  def default_url(version_name = "origin")
    "#{Figaro.env.upyun_upload_url}/image_load.png#{version_name}"
  end

  def url(version_name = "origin")
    @url ||= super({})
    version_name = version_name.to_s
    return @url if version_name.blank?
    [@url, version_name].join("!")
  end

  def ext
    file.extension.downcase
  end

  def extension_white_list
    %w[jpg jpeg gif png svg]
  end

  def filename
    if super.present?
      @name ||= SecureRandom.uuid
      "#{Time.now.year}/#{@name}.#{file.extension.downcase}"
    end
  end
end
